#@adminLayout() #define main()

<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="config-form">
                <div class="select-list">
                    <ul>
                        <li>名称：<input type="text" name="cname"
                                       style="width: 120px;" />
                        </li>

                        <li><a class="btn btn-primary btn-rounded btn-sm"
                               onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm"
                               onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="add()" id="btnadd"> <i
                    class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" id="btn_remove" style="display: none">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table" data-mobile-responsive="true"
                   style="table-layout: fixed; word-break: break-all;"></table>
        </div>
    </div>
</div>


<div class="modal fade" id="question-selector-modal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <form id="form-config-add" method="post"  class="form-horizontal m" >
                    <input id="id" name="id" type="hidden">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">名称：</label>
                        <div class="col-sm-8">
                            <input name="cname" class="form-control" type="text"
                                   required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">表达式：</label>
                        <div class="col-sm-8">
                            <input name="cronstr" class="form-control" type="text"
                                   required>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">执行类：</label>
                        <div class="col-sm-8">
                            <input class="form-control" name="jobclass" type="text" required/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">序号：</label>
                        <div class="col-sm-8">
                            <input name="isort" class="form-control" type="number" value="1"
                                   required>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭窗口</button>
                <button type="button" class="btn btn-primary" onclick="saveContent()">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>


<script type="text/javascript">
    var prefix ="#(ctx)/sys_cron";

    $(function() {
        var options = {
            url: prefix + "/list",
            removeUrl: prefix + "/remove",
            pageSize: 10,
            uniqueId: "id",
            sortName: "cname",
            sortOrder: "asc",
            modalName: "定时任务",
            columns: [{
                checkbox: true
            },{
                title: '序号',//标题  可不加,
                width:'60px',
                formatter: function (value, row, index) {
                    return index+1;
                }
            },
                {
                    field: 'id',
                    title: '任务编码',
                    width: '180px',
                },
                {
                    field: 'cname',
                    title: '任务名称',
                    width: '200px',
                },
                {
                    field: 'cronstr',
                    title: '任务cron',
                    width: '100px',
                },
                {
                    field: 'jobclass',
                    title: '执行类',
                    width: '220px',
                },
                {
                    field: 'cflag',
                    title: '启停状态',
                    width: '100px',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    },
                },
                {
                    title: '操作',
                    align: 'center',
                    width: '100px',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i> 编辑</a> ');

                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i> 删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        $("#bootstrap-table").colResizable({
            liveDrag:true,
            gripInnerHtml:"<div class='grip'></div>",
            draggingClass:"dragging",
            resizeMode:'overflow'
        });
    });

    function add()
    {
        $('#id').val('');
        $('#form-config-add')[0].reset();

        $("#question-selector-modal").modal({backdrop:true,keyboard:true});
    }
    //编辑属性
    function edit(id)
    {
        $("#question-selector-modal").modal({backdrop:true,keyboard:true});
        if(id!='')
        {
            $('#form-config-add').loadForm(prefix+'/getData?id='+id);
        }
    }
    //保存
    function saveContent() {
        if ($.validate.form("form-config-add")) {
            var options = {
                dataType : "json",
                url :prefix + "/save",
                data:{},
                success : function(data) {
                    if(data.code==0)
                    {
                        $.table.refresh();
                        $("#question-selector-modal").modal('hide');
                    }
                    else {
                        $.modal.alertError(data.msg);
                    }
                    $.modal.closeLoading();
                }
            };
            $("#form-config-add").ajaxSubmit(options);
        }
    }

    /* 调度任务状态显示 */
    function statusTools(row) {
        if (row.cflag == '0') {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="start(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="stop(\'' + row.id + '\')"></i> ';
        }
    }
    function start(id)
    {
        $.modal.confirm("确定要启动吗？",function(){
            $.operate.post(prefix+"/start", {id:id});
        });
    }
    function stop(id)
    {
        $.modal.confirm("确定要停止吗？",function(){
            $.operate.post(prefix+"/stop", {id:id});
        });
    }
</script>
</body>

#end
